package pure.engine.world 
{
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Stage;
	import flash.events.EventDispatcher;
	import flash.net.getClassByAlias;
	import pure.debug.Logger;
	import pure.engine.model.Entity;
	import pure.engine.model.IEntityFactory;
	import pure.engine.scenery.IScenery;
	import pure.engine.scenery.ImageScenery;
	import pure.engine.scenery.SceneryType;
	import pure.engine.scenery.TiledScenery;
	import pure.engine.core.SystemManager;
	import pure.engine.core.ns_despair;

	use namespace ns_despair;
	
	/**
	 * 游戏世界
	 * [Author] - PURE
	 * 
	 */
public class GameWorld extends World 
{
	public function GameWorld(RX:int, RY:int, regionData:Array = null)
	{
		super(RX, RY, regionData);
	}

	/**
	 * 生成简单实体
	 * 
	 * [Param] - layer  分层，简单实体多数为外层的表现效果，默认为-1000
	 * [Param] - name   名字
	 */
	public function createSimpleEntity(layer:int = -1000, name:String = 'entity'):Entity
	{
		var E:Entity = Entity.getEntity(name);
		
		E.m_layerIndex = layer;
		this.addModel(E);
		return E;
	}
	
	
	/**
	 * 生成最终实体
	 * 
	 * [Param] - alias  指定名字
	 * [Param] - wx     世界坐标x
	 * [Param] - wy     世界坐标x
	 * [Param] - args   参数
	 */
	public function createFinalEntity(alias:String, wx:Number, wy:Number, ...args):Entity 
	{
		var classObject:Object = getClassByAlias(alias);
		var factory:IEntityFactory = new classObject() as IEntityFactory;
		var E:Entity = Entity.getEntity(alias);
		
		E.m_layerIndex = factory.layerIndex;
		this.addModel(E);
		factory.produce(E, args)
		E.move(wx, wy);
		return E;
	}
	
	
	

	//public function createImageScenery(image:BitmapData, type:String = "steady"):IScenery
	//{
		//var scenery:IScenery = new ImageScenery(image, type);
		//m_sceneryList.push(scenery);
		//return scenery;
	//}
	//
	//
	//public function createTiledScenery(sheet:BitmapData, renderData:Array, tileSize:int, type:String = "steady"):IScenery
	//{
		//var scenery:IScenery = new TiledScenery(renderData, sheet, tileSize, type);
		//m_sceneryList.push(scenery);
		//return scenery;
	//}
	

	
	
	
	
	
	
	
	 
	 
	 
	/**
	 * 更新区域布景
	 * 
	 * @param area
	 * @param containers
	 */
	//ns_despair function updateSceneriesByArea(x:Number,y:Number,w:Number,h:Number, containers:Array):void 
	//{
		//var scenery:IScenery;
		//var len:int = m_sceneryList.length;
		//var bitmap:Bitmap;
		//var tx:Number;
		//var ty:Number;
		//
		//for (var i:int = 0; i < len; i++)
		//{
			//scenery = m_sceneryList[i];
			//bitmap = containers[i];
			//
			//switch(scenery.type)
			//{
				// 完全流动
				//case SceneryType.E_FLOW:
					//tx = (scenery.width - w) * tx / (w - m_width);
					//ty = (scenery.height - h) * ty / (h - m_height);
					//break;
				//
				// 水平流动
				//case SceneryType.H_FLOW:
					//tx = (scenery.width - w) * x / (w - m_width);
					//ty = - y;
					//break;
					//
				// 垂直流动
				//case SceneryType.V_FLOW:
					//tx = - tx;
					//ty = (scenery.height - h) * y / (h - m_height);
					//break;
//
				// 固定（Steady，Tile...）
				//default:
					//tx = - x;
					//ty = - y;
					//break;
			//}
			//
			//bitmap.x = tx;
			//bitmap.y = ty;
		//}
	//}

	



	/**
	 * 获取布景缓存
	 * 
	 * @see Monitor - ＃_makeAllBuffers
	 */
	//ns_despair function get sceneryBuffers():Array 
	//{ 
		//var buffers:Array = [];
		//var scenery:IScenery;
		//var len:int = m_sceneryList.length;
		//for (var i:int = 0; i < len; i++) 
		//{
			//scenery = m_sceneryList[i];
			//buffers.push(scenery.sceneryBuffer);
		//}
		//
		//return buffers;
	//}
	
	
	
	/**
	 * 清除全部
	 */
	//override ns_despair function clearAll():void
	//{
		//super.clearAll();
		//
		//var scenery:IScenery;
		//var len:int;
		//var i:int
//
		// 布景
		//len = m_sceneryList.length;
		//for (i = len - 1; i >= 0; i--) 
		//{
			//scenery = m_sceneryList[i];
			//scenery.destroy();
		//}
		//m_sceneryList  =  null;
	//}
	//
	
	 
	 
	
	
	//======================
	// Member
	//======================
	
	
	//ns_despair var m_sceneryList:Array = [];

}

}